<template>
  <div class="slider">
    <div class="banner-wrapper" ref="sliderRef">
      <div class="banner-content">
        <div class="banner" v-for="item in sliders" :key="item.id">
          <img :src="item.pic" alt="" />
        </div>
      </div>
    </div>
    <div class="dot-wrapper">
      <div
        class="dot"
        v-for="(item, index) in sliders"
        :key="item.id"
        :class="{ active: index === currentPage }"
      ></div>
    </div>
  </div>
</template>

<script>
import { ref } from 'vue'
import useSlider from '@/components/Base/Slider/useSlider'
export default {
  name: 'Slider',
  props: {
    sliders: {
      type: Array,
      require: true,
      default: () => [
        { id: 1, link: '', pic: '', content: 'a' },
        { id: 2, link: '', pic: '', content: 'b' },
        { id: 3, link: '', pic: '', content: 'c' },
        { id: 4, link: '', pic: '', content: 'd' },
        { id: 5, link: '', pic: '', content: 'e' }
      ]
    }
  },

  setup() {
    const sliderRef = ref(null)
    const { currentPage } = useSlider(sliderRef)

    return {
      sliderRef,
      currentPage
    }
  }
}
</script>

<style lang="scss" scoped>
.slider {
  position: relative;
  .banner-wrapper {
    min-height: 1px;
    overflow: hidden;
    .banner-content {
      height: 150px;
      white-space: nowrap;
      .banner {
        display: inline-block;
        width: 100%;
        height: 150px;
        text-align: center;
        > img {
          display: block;
          width: 100%;
          height: 100%;
          object-fit: cover;
        }
      }
    }
  }
  .dot-wrapper {
    position: absolute;
    left: 50%;
    transform: translate(-50%);
    bottom: 15px;
    .dot {
      display: inline-block;
      width: 8px;
      height: 8px;
      margin: 0 5px;
      border: 1px solid $color-button-little;
      border-radius: 50%;
      &.active {
        background-color: $color-button-little;
      }
    }
  }
}
</style>
